package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.anno.AutoFill;
import com.sky.entity.Setmeal;
import com.sky.enumeration.OperationType;
import com.sky.vo.SetmealVO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface SetmealMapper {

    @Select("select count(*) from setmeal where category_id = #{id} and status = 1")
    Integer countByCategory(Long id);

    @AutoFill(OperationType.INSERT)
    @Options(useGeneratedKeys = true,keyProperty = "id")
    @Insert("insert into setmeal (name, category_id, price, status,description,image, create_time, update_time, create_user, update_user) values (#{name}, #{categoryId}, #{price}, #{status}, #{description},#{image},#{createTime}, #{updateTime}, #{createUser}, #{updateUser})")
    void save(Setmeal setmeal);

    Page<SetmealVO> page(Integer categoryId, String name, Integer status);

    @Select("select * from setmeal where id=#{id}")
    SetmealVO getById(Integer id);

    @AutoFill(OperationType.UPDATE)
    void update(Setmeal setmeal);

    @Select("select status from setmeal where id = #{id}")
    Integer status(Long id);

    void delete(List<Long> ids);

    @Select("select * from setmeal where category_id = #{categoryId}")
    List<Setmeal> getSetmealByCategoryId(Integer categoryId);
}
